package pl.un4giv3n.mightvsmagic.utils.display;

import java.text.SimpleDateFormat;
import java.util.List;

import org.displaytag.decorator.TableDecorator;

import pl.un4giv3n.mightvsmagic.entity.ClanBattle;
import pl.un4giv3n.mightvsmagic.entity.FightReport;

public class ClanBattleDecorator extends TableDecorator {

	private static SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
	
	public String getDate(){
		ClanBattle battle = (ClanBattle) getCurrentRowObject();
		return sdf.format(battle.getDate());
	}
	
	public String getClashes(){
		ClanBattle battle = (ClanBattle) getCurrentRowObject();
		List<FightReport> fights = battle.getFights();
		StringBuilder sb = new StringBuilder();
		for (FightReport fightReport : fights) {
			sb.append("<a href='/showFightReport.action?fightId=").append(fightReport.getId()).append("' target='_blank'>");
			sb.append(fightReport.getAttackerLogin()).append(" vs ").append(fightReport.getDefenderLogin()).append(" - zwycięzca ").append(fightReport.getWinner());
			sb.append("</a><br/>");
		}
		return sb.toString();
	}
}
